/**
 * MIT License
 * 
 * Copyright (c) 2017 CaiDongyu
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
package org.axeidls.vo;

/**
 * Dao 分页配置
 * pageConfig必须放在@Sql注解的Dao方法的最后一个参数位置
 * @author CaiDongyu on 2016年5月9日 下午2:00:00.
 */
public final class PageConfig {

	/**
	 * 当前页码
	 */
	private int pageNum;
	/**
	 * 每页大小
	 */
	private int pageSize;
	/**
	 * 最大页长
	 */
	private int maxPageSize = 100;//默认100条最长，不可超过
	
	public PageConfig() {}
	
	public PageConfig(int pageNum, int pageSize) {
		this.pageNum = pageNum;
		this.pageSize = pageSize;
		init();
	}

	public PageConfig(int pageNum, int pageSize, int maxPageSize) {
		this.pageNum = pageNum;
		this.pageSize = pageSize;
		this.maxPageSize = maxPageSize;
		init();
	}
	
	private void init() {
		if(this.pageSize > this.maxPageSize) {
			throw new RuntimeException("PageConfig.pageSize "+this.pageSize+" > PageConfig.maxPageSize "+this.maxPageSize);
		}
		this.pageNum = this.pageNum < 1 ? 1:this.pageNum;
		this.pageSize = this.pageSize < 1 ? 1:this.pageSize;
	}

	public int getPageNum() {
		return pageNum;
	}

	public int getPageSize() {
		return pageSize;
	}

	public int getMaxPageSize() {
		return maxPageSize;
	}

	public void setMaxPageSize(int maxPageSize) {
		this.maxPageSize = maxPageSize;
	}

	public void setPageNum(int pageNum) {
		this.pageNum = pageNum;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
}
